<template>
    <div class="shop-car-wrap df">
        <div class="left fn df fdc aic jcc">
            <i class="iconfont icon-xiaolian"></i>
            <span>联系商家</span>
        </div>
        <div class="right df f1">
            <div class="car df" @click="filterFoodsData.length > 0 && (isShow = !isShow)">
                <div class="df jcc aic" :class="filterFoodsData.length > 0 ? 'car-left-active' : 'car-left'">
                    <van-icon name="shopping-cart" :color="filterFoodsData.length > 0 ? '#000' : '#999'" />
                    <van-badge v-show="reduceAcount" :content="reduceAcount" class="df aic jcc" />
                </div>
                <div class="car-right">
                    <h1><span>￥</span>
                        {{ reduceTotal }}</h1>
                    <div class="df car-content">
                        <p>另需配送费4元</p>
                        <p>支持自取</p>
                    </div>
                </div>

            </div>
            <div class="df aic jcc" :class="filterFoodsData.length > 0 ? 'money' : 'money-active'">
                <span v-if="filterFoodsData.length > 0">去结算</span>
                <span v-if="!filterFoodsData.length > 0" class="if-price">￥20元起送</span>
            </div>
        </div>
        <!-- 弹出框 -->
        <van-popup v-model="isShow" round position="bottom" :style="{ height: '50%' }">
            <div  class="new-user">
                新用户下单立减5元
            </div>
            <div class="shop-clear df jcsb">
                <div class="shop">购物车</div>
                <div class="clear" @click="clearShopCar">
                    清空购物车
                </div>
            </div>
            <div class="shop-content df jcsb aic" v-for="item in filterFoodsData" :key="item.id">
                <div class="title">{{ item.name }}</div>
                <div class="money">￥{{ item.price }}</div>
                <div class="df aic acount">
                    <van-button @click="ADD_ACOUNT(item.id)" class="add" round type="primary" size="mini">+</van-button>
                    <span class="num">{{ item.acount }}</span>
                    <van-button @click="REDUCE_ACOUNT(item.id)" round type="primary" size="mini">-</van-button>
                </div>
            </div>
        </van-popup>
    </div>
</template>

<script>
import { mapState, mapMutations, mapGetters, mapActions } from 'vuex';

export default {
    data() {
        return {
            isShow: false
        }
    },
    computed: {
        ...mapState('shop', ['goodsList']),
        ...mapGetters('shop', ['filterFoodsData', 'reduceTotal', 'reduceAcount']),
    },
    methods: {
        ...mapMutations('shop', ['ADD_ACOUNT', 'REDUCE_ACOUNT', 'CLEAR_CAR']),
        ...mapActions('shop', ['getGoodsData']),
        // 清空购物车
        async clearShopCar() {
            await this.getGoodsData()
            this.isShow = false
        }
    }
}
</script>

<style lang="scss" scoped>
.if-price {
    font-size: 12px;
    color: #fff;
}

.shop-car-wrap {
    background-color: #fff;
    width: 100%;
    height: 60px;
    border-radius: 40px;
    overflow: hidden;

    .left {
        height: 100%;
        background-color: #222;
        width: 70px;
        color: #999;
        position: relative;
        z-index: 100000;

        i {
            font-size: 20px;
        }

        span {
            font-size: 12px;
            margin-top: 2px;
        }
    }

    .right {
        background-color: #222;
        margin-left: 5px;
        position: relative;
        z-index: 100000;

        .car {
            height: 100%;
            background-color: #222;
            padding: 5px 10px;

            // 激活样式
            .car-left-active {
                width: 50px;
                height: 50px;
                border-radius: 50%;
                background-color: #ffc300;
                position: relative;

                .van-icon {
                    font-size: 30px;

                }

                .van-badge {
                    position: absolute;
                    top: -2px;
                    right: 0;
                    font-size: 10px;
                    width: 20px;
                    height: 20px;
                    border: none;
                }
            }

            .car-left {
                width: 50px;
                height: 50px;
                border-radius: 50%;
                background-color: #333333;
                position: relative;

                .van-icon {
                    font-size: 30px;

                }

                .van-badge {
                    position: absolute;
                    top: -2px;
                    right: 0;
                    font-size: 10px;
                    width: 20px;
                    height: 20px;
                    border: none;
                }
            }

            .car-right {
                padding: 5px 10px;

                h1 {
                    color: #fff;
                    font-size: 22px;

                    span {
                        font-size: 16px;
                    }
                }

                .car-content {
                    color: #999;
                    font-size: 12px;

                    p {
                        margin-top: 2px;
                        padding: 0 5px;

                        &:nth-child(1) {
                            border-right: 1px solid #999;
                        }
                    }
                }
            }
        }

        .money {
            height: 100%;
            background-color: #ffc300;
            width: 80px;
            position: absolute;
            right: 0;
            font-weight: bold;
        }

        .money-active {
            height: 100%;
            background-color: #222222;
            width: 80px;
            position: absolute;
            right: 0;
            font-weight: bold;
        }
    }

    .van-popup {
        padding-bottom: 60px;
    }


    .acount {
        flex-direction: row-reverse;

        .num {
            font-size: 18px;
            margin: 0 2px 0 4px;
        }
    }

    .van-button {
        text-align: center;
        line-height: 22px;
        border-radius: 50%;
        width: 25px;
        height: 25px;
        background-color: #fff;
        border: 1px solid #999;
        color: #999;
        font-size: 20px;
    }

    .add {
        border: none;
        background-color: #ffc300;
        color: #000;
    }
}

.car-left-active {
    background-color: #333333;

    .car-active {
        background-color: #999999;
    }
}

// 抽屉里面的样式
.new-user {
    height: 40px;
    background-color: #fee7c8;
    color: #f5552c;
    text-align: center;
    line-height: 40px;
}

.shop-clear {
    padding: 0 15px;
    margin: 20px 0;
    font-size: 14px;

    .clear {
        color: #999;

    }
}

.shop-content {
    padding: 0 15px;
    margin: 20px 0;

    .title {
        font-size: 16px;
        font-weight: bold;
    }

    .money {
        font-size: 18px;
        color: #f5552c;
        font-weight: bold;
    }
}
</style>